package jp.oesf.rssreader;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class Detail extends Activity {
    private Cursor cursor;
    private String link;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.detail);

        Bundle extras = getIntent().getExtras();
		long id = extras.getLong("id");

		RssSQLiteOpenHelper databaseOpenHelper = new RssSQLiteOpenHelper(this);
        SQLiteDatabase database = databaseOpenHelper.getReadableDatabase();
        cursor = database.query(RssSQLiteOpenHelper.RSS_TABLE,null,"_id="+id,null,null,null,null);
		try {
	        if (cursor != null) {
	        	startManagingCursor(cursor);

	        	cursor.moveToFirst();
	        	((TextView)findViewById(R.id.detail_description)).setText
	        		(cursor.getString(cursor.getColumnIndex("description")));
	        	link = cursor.getString(cursor.getColumnIndex("link"));
	        }
	    	databaseOpenHelper.close();
			
		} catch (Exception e) {
			e.printStackTrace();
		}

    }
    public void onClickLinkButton(View v) {
        try {
            //リンク先（Webページ）の表示
            Intent intent=new Intent("android.intent.action.VIEW",
                Uri.parse(link));
            startActivity(intent);
        } catch (Exception e) {
        	Toast.makeText(this, "リンク先を表示できません", Toast.LENGTH_LONG).show();
        }
    }
}